// Copyright @ ChenChao


#include "DataAssets/StartUp/DataAsset_StartUpDataBase.h"

#include "AbilitySystem/WarriorAbilitySystemComponent.h"
#include "AbilitySystem/GameplayAbilities/WarriorGameplayAbility.h"

void UDataAsset_StartUpDataBase::GiveToAbilitySystemComponent(UWarriorAbilitySystemComponent* InWarriorASCToGive,
                                                              int32 ApplyLevel)
{
	check(InWarriorASCToGive);
	GrantAbilities(ActivateOnGivenAbilities, InWarriorASCToGive, ApplyLevel);
	GrantAbilities(ReactiveAbilities, InWarriorASCToGive, ApplyLevel);
}

void UDataAsset_StartUpDataBase::GrantAbilities(const TArray<TSubclassOf<UWarriorGameplayAbility>>& InAbilitiesToGive,
	UWarriorAbilitySystemComponent* InWarriorASCToGive, int32 ApplyLevel)
{
	if (InAbilitiesToGive.IsEmpty()) return;

	for (const TSubclassOf<UWarriorGameplayAbility>& Ability : InAbilitiesToGive)
	{
		if (! Ability) continue;
		
		FGameplayAbilitySpec AbilitySpec(Ability);		//设置技能类引用
		AbilitySpec.SourceObject = InWarriorASCToGive->GetAvatarActor();  //指定技能源对象为角色Avatar
		AbilitySpec.Level = ApplyLevel;		//配置技能初始等级
		
		InWarriorASCToGive->GiveAbility(AbilitySpec);	//将技能授予目标组件
	}
}
